package com.niit.covid.topThree;


import com.niit.covid.bean.CovidBean;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author:Yan
 * @date: 2022年08月12日 17:37
 * @desc:
 */
public class CovidTopThreeReducer extends Reducer<CovidBean, LongWritable,CovidBean, NullWritable> {

    @Override
    protected void reduce(CovidBean key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {

        //不遍历迭代器，此时的key就是分组中的第一个key就是州的确诊人数最多对应的数据，取出每组的前3
        //在reduce端利用自定义分组规则，

        int num = 0;
        for (LongWritable value:values){
            if (num<3){
                context.write(key,NullWritable.get());
                num+=1;
            }else {
                return;
            }
        }

    }
}
